#include "MinCutBasedSegmentationModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.min_cut_based_segmentation_model.json";
}

MinCutBasedSegmentationModel::MinCutBasedSegmentationModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/min_cut_segmentation.html");
}

MinCutBasedSegmentationModel& MinCutBasedSegmentationModel::get()
{
    static MinCutBasedSegmentationModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void MinCutBasedSegmentationModel::fromJson(const QJsonObject& json, QStringList& errorList)
{

    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    bgPointX_ = json["bgPointX"].toDouble(bgPointX_);
    bgPointY_ = json["bgPointY"].toDouble(bgPointY_);
    bgPointZ_ = json["bgPointZ"].toDouble(bgPointZ_);

    segSigma_ = json["segSigma"].toDouble(segSigma_);
    segRadius_ = json["segRadius"].toDouble(segRadius_);
    segNumberOfNeighbours_ = json["segNumberOfNeighbours"].toInt(segNumberOfNeighbours_);
    segSourceWeight_ = json["segSourceWeight"].toDouble(segSourceWeight_);
}

QJsonObject MinCutBasedSegmentationModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("bgPointX", QJsonValue(bgPointX_));
    json.insert("bgPointY", QJsonValue(bgPointY_));
    json.insert("bgPointZ", QJsonValue(bgPointZ_));

    json.insert("segSigma", QJsonValue(segSigma_));
    json.insert("segRadius", QJsonValue(segRadius_));
    json.insert("segNumberOfNeighbours", QJsonValue(segNumberOfNeighbours_));
    json.insert("segSourceWeight", QJsonValue(segSourceWeight_));

    return json;
}
